<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" action="" method="post" lay-filter = "editObj">
            <input type="hidden" name="id"/>
            <div class="layui-form-item">
                <label for="categoryCode" class="layui-form-label">
                    图书类别编号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="categoryCode" name="categoryCode" minlength="3" maxlength="20" lay-verify="range"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="categoryName" class="layui-form-label">
                    图书类别名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="categoryName" name="categoryName" minlength="2" maxlength="20" lay-verify="range"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="remark" class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="edit" lay-submit="">
                    确认修改
                </button>
            </div>
        </form>
    </div>
</div>
<script th:inline="javascript">
    layui.use(['form','jquery','validate','tool'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var validate = layui.validate;
        var baseUrl = "/back/category";
        var tool = layui.tool;
        var bookCategory = [[${bookCategory}]];
        init_form();

        /**
         * 初始化页面
         */
        function init_form() {
            form.val('editObj',{
                "id":bookCategory.id
                ,"categoryCode":bookCategory.categoryCode
                ,"categoryName":bookCategory.categoryName
                ,"remark":bookCategory.remark
            });
        }

        //添加表单校验
        form.verify(validate);

        //监听提交
        form.on('submit(edit)', function(data){
            var res = tool.submit(baseUrl + '/edit',data.field);
            if(res.code == return_200){
                layer.msg(res.msg, {
                        icon: msg.success,
                        time: 2000
                    },
                    function(){
                        xadmin.father_reload();
                    }
                );
            }else {
                layer.msg(res.msg, {
                        icon: msg.error,
                        time: 2000
                    },
                    function(){
                        xadmin.father_reload();
                    }
                );
            }
            return false;
        });
    });
</script>
</body>
</html>